package www.icomwell.com.viperdemo.Modules.List.UserInterface.View;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.zip.Inflater;

import www.icomwell.com.viperdemo.Modules.List.UserInterface.Presenter.DisplayData;
import www.icomwell.com.viperdemo.R;

/**
 * Created by leeesven on 17/5/23.
 */

public class ListAdapter extends BaseAdapter {

	private List<DisplayData> displayDataList;

	public ListAdapter(){}

	public ListAdapter(List<DisplayData> displayDatas){
		this.displayDataList = displayDatas;
	}

	public void setDisplayDataList(List<DisplayData> displayDataList) {
		this.displayDataList = displayDataList;
	}

	@Override
	public int getCount() {
		if (displayDataList == null) {
			return 0;
		} else {
			return displayDataList.size();
		}
	}

	@Override
	public Object getItem(int i) {
		return this.displayDataList.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View convertView, ViewGroup parent) {
		if (convertView == null){
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_list_item, parent, false);
			DisplayItemHolder displayItemHolder = new DisplayItemHolder();
			displayItemHolder.nameText = (TextView) convertView.findViewById(R.id.contact_name);
			convertView.setTag(displayItemHolder);
		}
		DisplayData displayData = (DisplayData) getItem(i);
		DisplayItemHolder displayItemHolder = (DisplayItemHolder) convertView.getTag();
		displayItemHolder.nameText.setText(displayData.getTitle());
		return convertView;
	}

	static class DisplayItemHolder{
		public TextView nameText;
	}

}
